<?php

include_once 'Expression.php';
include_once 'PrimitiveExpression.php';
include_once 'TypeReference.php';

/**
 * Represents a parameter declaration for a method
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ParameterDeclarationExpressionExample.php 
 */

class ParameterDeclarationExpression extends Expression
{
    /**
     * The ParameterDeclarationExpression constructor
     * 
     * @param type $name The name of the parameter
     */
    
    public function __construct($name)
    {
        parent::__construct();
        $this->set_Name($name);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Name')
        {
            $this->set_Name($value);
        }
        
        if($name == 'ByReference')
        {
            $this->set_ByReference($value);
        }
        
        if($name == 'TypeHint')
        {
            $this->set_TypeHint($value);
        }
        
        if($name == 'HasDefaultValue')
        {
            $this->set_HasDefaultValue($value);
        }
        
        if($name == 'DefaultValue')
        {
            $this->set_DefaultValue($value);
        }
    }    
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Name')
        {
            return $this->get_Name();
        }
        
        if($name == 'ByReference')
        {
            return $this->get_ByReference();
        }
        
        if($name == 'TypeHint')
        {
            return $this->get_TypeHint();
        }
        
        if($name == 'HasDefaultValue')
        {
            return $this->get_HasDefaultValue();
        }
        
        if($name == 'DafaultValue')
        {
            return $this->get_DefaultValue();
        }
    }    
    
    /**
     * The $Name getter method
     * @return string 
     */
    
    public function get_Name()
    {
        return $this->Name;
    }

    /**
     * The $Name setter method
     * @param string $name
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert (true) throws InvalidArgumentException
     */
    
    public function set_Name($name)
    {
        if(is_string($name))
        {
            $this->Name = $name;
        }
        else
        {
            throw new InvalidArgumentException(
                'The method name must be a string.');
        }
    }

    /**
     * The $ByReference getter method
     * @return bool 
     */
    
    public function get_ByReference()
    {
        return $this->ByReference;
    }

    /**
     * The $ByReference setter method
     * @param bool $byReference
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert ('myString') throws InvalidArgumentException
     */
    
    public function set_ByReference($byReference)
    {
        if(is_bool($byReference))
        {
            $this->ByReference = $byReference;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be boolean.');
        }
    }

    /**
     * The $TypeHint getter method
     * @return TypeReference 
     */
    
    public function get_TypeHint()
    {
        return $this->TypeHint;
    }

    /**
     * The $TypeHint setter method
     * @param TypeReference $typeHint 
     */
    
    public function set_TypeHint(TypeReference $typeHint)
    {
        $this->TypeHint = $typeHint;
    }

    /**
     * The $HasDefaultValue getter method
     * @return bool 
     */
    
    public function get_HasDefaultValue()
    {
        return $this->HasDefaultValue;
    }
    
    /**
     * The $HasDefaultValue setter method
     * 
     * If $HasDefaultValue is set to true without setting $DefaultValue
     * to an instance of the PrimitiveExpression class
     * the default value of the parameter will be null
     * 
     * @param bool $hasDefaultValue
     * @throws InvalidArgumentException 
     * 
     * @assert (123) throws InvalidArgumentException
     * @assert ('myString') throws InvalidArgumentException
     */

    public function set_HasDefaultValue($hasDefaultValue)
    {
        if(is_bool($hasDefaultValue))
        {
            $this->HasDefaultValue = $hasDefaultValue;
        }
        else
        {
            throw new InvalidArgumentException(
                'The value must be boolean.');
        }
    }

    /**
     * The $DefaultValue getter method
     * @return PrimitiveExpression 
     */
    
    public function get_DefaultValue()
    {
        return $this->DefaultValue;
    }

    /**
     * The $DefaultValue setter method
     * @param PrimitiveExpression $defaultValue 
     */
    
    public function set_DefaultValue(PrimitiveExpression $defaultValue = null)
    {
        if($defaultValue != null)
        {    
            $this->DefaultValue = $defaultValue;
            $this->HasDefaultValue = true;
        }
        else
        {
            $this->DefaultValue = null;
            $this->HasDefaultValue = false;
        }
    }
    
    /**
     * The name of the parameter
     * @var string 
     */
    
    private $Name;
    
    /**
     * Is the parameter passed by reference
     * @var bool 
     */
    
    private $ByReference = false;
    
    /**
     * The type hint for the parameter
     * @var TypeReference 
     */
    
    private $TypeHint = null;
    
    /**
     * Does the parameter have a default value
     * @var bool 
     */
    
    private $HasDefaultValue = false;
    
    /**
     * The parameter default value
     * @var PrimitiveExpression 
     */
    
    private $DefaultValue;
}

?>
